package com.lee.wordcount;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class WordCountMapper extends Mapper<LongWritable, Text, Text, IntWritable> {

    /**
     * 这个方法会每行调用一次
     *
     * @param key     偏移量
     * @param value   内容
     * @param context 上下文对象，用于传输
     */
    @Override
    protected void map(LongWritable key, Text value, Context context)
            throws IOException, InterruptedException {

        String line = value.toString();
        String[] words = line.split(" ");
        for (String w : words) {
            context.write(new Text(w), new IntWritable(1));
        }

    }
}
